<?php
namespace Poi\EttsBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Poi\EttsBundle\Model\Officer;
use Poi\EttsBundle\Model\Officers;

/**
 * @author Ricardo J. Vazquez
 * 
 * Controller class to handle requests for Officers
 */
class OfficerController extends Controller
{
	private $conn = null; //Connection
	
	/**
	* Returns response with either a single or collection of Officer models.
	*
	* @param $badge badge number of the officer
	* @return Response with collection or model of Officer in xml format
	*/
    public function indexAction($badge) {
		$this->conn = $this->get('doctrine.dbal.default_connection');
		
		if($badge != 'nil'){
			$o = new Officer($this->conn, $badge);	
			
			$r = new Response($o->toXML());
			$r->headers->set('Content-Type', 'text/xml');
			
			return $r;
		}
		
		$os = new Officers($this->conn);
		//Create new function
		$os->setLoadCallback('loadOfficers','Officer',$os);
		
		$r = new Response($os->toXML());
		$r->headers->set('Content-Type', 'text/xml');
		
		return $r;
    }

	/**
	* Returns response with status of the write
	*
	* @param $badge badge number of the officer
	* @return Response with status of the write in xml format
	*/
    public function newAction($badge) {
    }

	/**
	* Returns response with status of the modify
	*
	* @param $badge badge number of the officer
	* @return Response with status of the modify in xml format
	*/
	public function updateAction($badge) {
	}
	
	/**
	* Returns response with status of the delete
	*
	* @param $badge badge number of the officer
	* @return Response with status of the delete in xml format
	*/
	public function removeAction($badge) {
	}
}